<template>
    <rx-layout>
        <div slot="left" width="220" showButton="true">
            <rx-fit>
                <rx-category-treeeditor
                    cat-key="FORM"
                    :statisticConfig="statisticConfig"
                    :edit="true"
                    @handSelect="handSelect"
                    :async="true"
                    v-if="isShowManageTree"
                    :isAdmin="isManageToTree"
                    :checkToDel="true"
                ></rx-category-treeeditor>
            </rx-fit>
        </div>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <a-button icon="plus" type="primary" @click="add">{{ $ti18('rxList.newBtn', '新建') }}</a-button>
                        <a-button v-if="selectedRowKeys.length > 0"
                                  type="primary"
                                  icon="switcher" @click="openCategoryDialog">
                            {{$ti18('rxList.changeCategory','切换分类')}}
                        </a-button>
                        <a-dropdown
                            v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{ $ti18('rxList.moreBtn', '更多') }}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0" @click="editOne">
                                    <a-icon type="edit"/>
                                    {{ $ti18('rxList.editBtn', '编辑') }}
                                </a-menu-item>
                                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0"
                                             @click="delByIds(selectedRowKeys)">
                                    <a-icon type="delete"/>
                                    {{ $ti18('rxList.delBtn', '删除') }}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i
                    class="iconfont iconguolv"></i>{{ $ti18('rxList.leachBtn', '过滤') }}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.key','项目别名')">
                            <a-input :placeholder="i18n('form.key','请输入项目别名','input')"
                                     v-model="queryParam.Q_KEY__S_LK"/>
                        </a-form-item>
                        <a-form-item :label="i18n('form.name','项目名称')">
                            <a-input :placeholder="i18n('form.name','请输入项目名称','input')"
                                     v-model="queryParam.Q_NAME__S_LK"/>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-form/form/codegen/formCodegenProject/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
          <span slot="status" slot-scope="{ text,record }">
            <a-tag :color="statusMap[text].color">
                <span>{{ statusMap[text].text }}</span>
              </a-tag>
          </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span @click="edit(record)">{{ $ti18('rxList.editBtn', '编辑') }}</span>
            <span @click="delByIds([record.id])">{{ $ti18('rxList.delBtn', '删除') }}</span>
          </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import FormCodegenProjectApi from '@/api/form/codegen/formCodegenProject'
import FormCodegenProjectEdit from './projectEdit/FormCodegenProjectEdit'
import {BaseList, RxFit, RxGrid} from "@lowcode/jpaas-common-lib";
import RxCategoryTreeeditor from '@/components/redxun/rx-category-treeeditor';
import ChangeCategory from "@/views/modules/share/ChangeCategory.js"
export default {
    name: 'FormCodegenProjectList',
    mixins: [BaseList,ChangeCategory],
    components: {
        RxFit,
        RxCategoryTreeeditor
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index', '序号'),
                    type: 'indexColumn',
                    width: 100,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.key', '项目别名'), dataIndex: 'key', width: 100},
                {title: this.i18n('form.name', '项目名称'), dataIndex: 'name', width: 100},
                {
                    title: this.i18n('form.status', '状态'),
                    dataIndex: 'status',
                    width: 100,
                    scopedSlots: {customRender: 'status'}
                },
                {
                    title: this.$ti18('rxList.action', '操作'),
                    width: 100,
                    dataIndex: 'action',
                    scopedSlots: {customRender: 'action'}
                }
            ],
            component: FormCodegenProjectEdit,
            comment: this.i18n('list.comment', '空项目代码生成表'),
            fitSearch: false,
            curTree: {},
            statusMap: {
                'YES': {color: 'green', text: this.i18n('list.YES', '已配置')},
                'NO': {color: 'blue', text: this.i18n('list.NO', '未配置')}
            },
            statisticConfig: {
                type: "static_form",
                table: "FORM_CODEGEN_PROJECT t",
                field: "TREE_ID_",
                whereConf: []
            },
            //变更分类配置
            categoryConfig:{
                Api:FormCodegenProjectApi,
                catKey:"FORM",
                gridRef:"table"
            }
        }
    },
    created() {
        this.isUserManager(this.$route.query.appId);
        this.needFilterAppId();
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "formCodegenProject", key);
        },
        delById(ids) {
            return FormCodegenProjectApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return FormCodegenProjectApi.query(parameter)
        },
        codeGen(record) {
            if (record.status != "YES") {
                this.$message.warning(this.i18n('msg.noConfigTip', '未配置完代码生成,请继续完善！'));
                return;
            }
            FormCodegenProjectApi.genCode(record.id);
        },
        handSelect(curRow) {
            this.curTree = curRow;
            var treeId = curRow.treeId;
            if (treeId != "0") {
                this.queryParam.Q_TREE_ID__S_EQ = treeId;
            } else {
                delete this.queryParam.Q_TREE_ID__S_EQ;
            }
            this.loadData(this.queryParam);
        }
    }
}
</script>
<style scoped>
.table-operator {
    padding: 4px;
}

.table-operator button {
    margin: 2px;
}
</style>

